package org.kfish.framework;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.kfish.framework.helper.AopHelper;
import org.kfish.framework.helper.BeanHelper;
import org.kfish.framework.helper.ClassHelper;
import org.kfish.framework.helper.ConfigHelper;
import org.kfish.framework.helper.ControllerHelper;
import org.kfish.framework.helper.EmbeddedConfigHelper;
import org.kfish.framework.helper.IocHelper;
import org.kfish.framework.log.Log;
import org.kfish.framework.util.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 加载 相应的 Helper 类
 * 
 * @author CK
 *
 */
public class HelperLoader {
	private static final Logger LOGGER = LoggerFactory.getLogger(HelperLoader.class);
	
	static {
		// 初始化日志类
		URL resource = HelperLoader.class.getClassLoader().getResource(ConfigHelper.getLogFile());
		if (resource != null) {
			try (InputStream in = resource.openStream()) {
				Log.init(in);
			} catch (IOException e) {
				LOGGER.error("init log config failure.", e);
				throw new RuntimeException(e);
			}
		}

	}

	public static void init() {
		Class<?>[] classList = { ClassHelper.class, BeanHelper.class,EmbeddedConfigHelper.class,AopHelper.class, IocHelper.class,
				ControllerHelper.class };

		for (Class<?> cls : classList) {
			ClassUtil.loadClass(cls.getName());
		}

	}
}
